package me.zhengjie.business.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.business.domain.Zhsq;
import me.zhengjie.business.domain.vo.*;
import me.zhengjie.business.repository.ZhsqRepository;
import me.zhengjie.business.service.HomeService;
import me.zhengjie.config.DebugProperties;
import me.zhengjie.pay.domain.QueryRefundVo;
import me.zhengjie.utils.PageUtil;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @website https://el-admin.vip
 * @description 首页查询
 * @author xiahongbo
 * @date 2022-10-15
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class HomeServiceImpl implements HomeService {

    private final ZhsqRepository zhsqRepository;

    @Override
    public JSONObject queryGk(String gsid, String ylddbm) {
        JSONObject obj = new JSONObject();
        if(!DebugProperties.debug) {
            Object o = zhsqRepository.queryGk(gsid, ylddbm);
            Object[] arr = (Object[]) o;
            obj.put("sqrs", arr[0]);
            obj.put("pgcg", arr[1]);
            obj.put("pgrc", arr[2]);
            obj.put("pgfy", arr[3]);
            obj.put("sqcg", arr[4]);
            obj.put("ygs", arr[5]);
            obj.put("yqy", arr[6]);
            obj.put("yfw", arr[7]);
            obj.put("fwrc", arr[8]);
        } else {
            obj.put("sqrs", 35);
            obj.put("pgcg", 22);
            obj.put("pgrc", 2);
            obj.put("pgfy", 600);
            obj.put("sqcg", 20);
            obj.put("ygs", 17);
            obj.put("yqy", 13);
            obj.put("yfw", 13);
            obj.put("fwrc", 198);
        }

        return obj;
    }

    @Override
    public JSONObject querySettle(String gsid) {
        JSONObject obj = new JSONObject();
        JSONArray zgArray = new JSONArray();
        JSONArray jmArray = new JSONArray();
        List<Object> list = zhsqRepository.querySettle("");
        log.info("queryAmount: {}", list);

        JSONArray timeArray = new JSONArray();
        timeArray.add("2022");
        timeArray.add("2023");
        timeArray.add("2024");
        for (int i = 0; i < list.size(); i++) {
            Object o = list.get(i);
            Object[] arr = (Object[]) o;

            String CJT100 = arr[1].toString().trim();
            String AKB068 = arr[2].toString();

            if("居民".equals(CJT100)) {
                jmArray.add(AKB068);
            }
            if("职工".equals(CJT100)) {
                zgArray.add(AKB068);
            }

        }
        obj.put("monthArray", timeArray);
        obj.put("jmArray", jmArray);
        obj.put("zgArray", zgArray);

        return obj;
    }

    @Override
    public JSONObject queryArea(String gsid) {
        JSONObject obj = new JSONObject();
        if(!DebugProperties.debug) {
            JSONArray arrayArea = new JSONArray();
            JSONArray arrayValue = new JSONArray();
            List<Object> list = zhsqRepository.queryArea(gsid);
            for (Object o: list) {
                Object[] arr = (Object[]) o;

                arrayValue.add(arr[0]);
                arrayArea.add(arr[2]);
            }
            obj.put("area", arrayArea);
            obj.put("value", arrayValue);
        } else {

            JSONArray arrayArea = new JSONArray();
            arrayArea.add("南关区");
            arrayArea.add("宽城区");
            arrayArea.add("朝阳区");
            arrayArea.add("二道区");
            arrayArea.add("绿园区");
            arrayArea.add("双阳区");
            arrayArea.add("九台区");
            arrayArea.add("农安县");
            arrayArea.add("榆树市");
            arrayArea.add("德惠市");
            arrayArea.add("公主岭市");

            obj.put("area", arrayArea);


            JSONArray arrayValue = new JSONArray();
            arrayValue.add(97);
            arrayValue.add(0);
            arrayValue.add(0);
            arrayValue.add(85);
            arrayValue.add(0);
            arrayValue.add(0);
            arrayValue.add(0);
            arrayValue.add(0);
            arrayValue.add(0);
            arrayValue.add(0);
            arrayValue.add(0);
            obj.put("value", arrayValue);
        }

        return obj;
    }

    @Override
    public Map<String, Object> queryYsq(String blurry, String area, String ylddbm, String gsid, Pageable pageable) {
        Page<ZhgkxmVo> page =  zhsqRepository.queryYsq(blurry, area, ylddbm, gsid, pageable);
        return PageUtil.toPage(page);
    }

    @Override
    public Map<String, Object> queryPgcg(String blurry, String area, String ylddbm, Pageable pageable) {
        Page<ZhgkxmVo> page =  zhsqRepository.queryPgcg(blurry, area, ylddbm, pageable);
        return PageUtil.toPage(page);
    }

    @Override
    public Map<String, Object> queryPgrc(String blurry, String area, String ylddbm, String sftg, Pageable pageable) {
        Page<ZhgkPgrcVo> page =  zhsqRepository.queryPgrc(blurry, area, ylddbm, sftg, pageable);
        return PageUtil.toPage(page);
    }

    @Override
    public Map<String, Object> querySqcg(String blurry, String area, String ylddbm, Pageable pageable) {
        Page<ZhgkSqcgVo> page =  zhsqRepository.querySqcg(blurry, area, ylddbm, pageable);
        return PageUtil.toPage(page);
    }

    @Override
    public Map<String, Object> queryYgs(String blurry, String area, String ylddbm, String gszt, Pageable pageable) {
        Page<ZhgkGsVo> page =  zhsqRepository.queryYgs(blurry, area, ylddbm, gszt, pageable);
        return PageUtil.toPage(page);
    }

    @Override
    public Map<String, Object> queryYqy(String blurry, String area, String ylddbm, String qyzt, Pageable pageable) {
        Page<ZhgkQyVo> page =  zhsqRepository.queryYqy(blurry, area, ylddbm, qyzt, pageable);
        return PageUtil.toPage(page);
    }

    @Override
    public Map<String, Object> queryPgfymx(String blurry, String area, String ylddbm, String qyzt, Pageable pageable) {
        Page<ZhgkPgfymxVo> page =  zhsqRepository.queryPgfymx(blurry, area, ylddbm, qyzt, pageable);
        return PageUtil.toPage(page);
    }

    @Override
    public Map<String, Object> queryYfw(String blurry, String area, String ylddbm, Pageable pageable) {
        Page<ZhgkxmVo> page =  zhsqRepository.queryYfw(blurry, area, ylddbm, pageable);
        return PageUtil.toPage(page);
    }

    @Override
    public Map<String, Object> queryFwrc(String blurry, String area, String ylddbm, String orderZt, Pageable pageable) {
        Page<ZhgkFwrcVo> page =  zhsqRepository.queryFwrc(blurry, area, ylddbm, orderZt, pageable);
        return PageUtil.toPage(page);
    }
}
